
Router.configure({
  // we use the  appBody template to define the layout for the entire app
  layoutTemplate: 'appBody',

  // the appNotFound template is used for unknown routes and missing lists
  notFoundTemplate: 'appNotFound',

  // show the appLoading template whilst the subscriptions below load their data
  loadingTemplate: 'appLoading',

  // wait on the following subscriptions before rendering the page to ensure
  // the data it's expecting is present
  waitOn: function () {
    return [
      // Meteor.subscribe('publicLists'),
      Meteor.subscribe('publish')
    ];
  }
});

dataReadyHold = null;
Meteor.startup(function () {
  Meteor.CURRENT = {
      PUSHLISH:'CURRENT.PUSHLISH'
  };
  //正则验证规则
  Meteor.regexp = {
    phone:/1\d{10}/, //手机
    password:/[a-zA-Z0-9]{6,12}/, //密码6-12位
    ID:/\w{15,}/, //密码6-12位
  };
  Router.onBeforeAction(function () {
      this.params.pid && Meteor.regexp.ID.test(this.params.pid) && Session.set(Meteor.CURRENT.PUSHLISH, this.params.pid);
      this.next();
  }, {except: ['join', 'signin']});

})
if (Meteor.isClient) {
  // Keep showing the launch screen on mobile devices until we have loaded
  // the app's data

  dataReadyHold = LaunchScreen.hold();

  // Show the loading screen on desktop
  Router.onBeforeAction('loading', { except: ['join', 'signin'] });
  Router.onBeforeAction('dataNotFound', { except: ['join', 'signin'] });
}

Router.route('join');
Router.route('signin');
Router.route('logout',function () {
  Meteor.logout();
  this.redirect('signin');
});

Router.route('publish',{
  onBeforeAction:function () {
    if(!Meteor.user()){
      return this.redirect('signin');
    }
    this.next();
  }
});//发布
Router.route("mainSection");
Router.route('/',function () {
  this.redirect('mainSection');
})
// Router.route('details');
Router.route('/publish/:pid',{

  template:'details',
})
// task
// Router.route('listsShow', {
//   path: '/lists/:_id',
//   // subscribe to todos before the page is rendered but don't wait on the
//   // subscription, we'll just render the items as they arrive
//   onBeforeAction: function () {
//     this.todosHandle = Meteor.subscribe('todos', this.params._id);
//
//     if (this.ready()) {
//       // Handle for launch screen defined in app-body.js
//       dataReadyHold.release();
//     }
//     this.next();
//   },
//   data: function () {
//     return Lists.findOne(this.params._id);
//   },
//   action: function () {
//     this.render();
//   }
// });

// Router.route('/', function () {
//   this.redirect('mainPage');
// });

//notes
// Router.route('note',{layoutTemplate:'noteLayout'})
// Router.route('/news');
// Router.route('/study');
// Router.route('/todos/:_id?', {
//   name: 'todos',
//   onBeforeAction: function () {
//     if(this.params._id){
//       this.todosHandle = Meteor.subscribe('todos', this.params._id);
//
//       if (this.ready()) {
//         // Handle for launch screen defined in app-body.js
//         dataReadyHold.release();
//       }
//     }
//     this.next();
//   },
//   data: function () {
//     if(this.params._id){
//       return Lists.findOne(this.params._id);
//     }else {
//       return [];
//     }
//   },
// });
// Router.route('/note');

// Router.route('noteNew',{
//     path:'/note/new',
//     layoutTemplate:'noteLayout'
// })
